package cn.wolfcode.shop.api.query;


import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

@Getter
@Setter
public class PageResult implements Serializable {

    public static final PageResult EMPTY_PAGE = new PageResult(Collections.EMPTY_LIST, 0, 1, 1);

    private List<?> data;

    private int totalCount;

    private int currentPage =1;


    private int pageSize =5;

    private int totalPage;
    private int prevPage;
    private int nextPage;

    public PageResult(List<?> data, int totalCount, int currentPage, int pageSize) {
        this.data = data;
        this.totalCount = totalCount;
        this.currentPage = currentPage;
        this.pageSize = pageSize;

        this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage - 1 > 0 ? currentPage - 1 : 1;
        this.nextPage = currentPage + 1 > totalPage ? totalPage : currentPage + 1;

    }

    public PageResult() {
    }
}
